<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/font-awesome.css" rel="stylesheet">
    <link href="/css/datatables.min.css" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css" rel="stylesheet">
    <script src="/js/jquery-3.1.1.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/vue.js"></script>
</head>
<body style="background-color:whitesmoke">
<div id="admin">
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-lg-10">
            <h2>审批中心</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="../../templates/index.html">审核中心</a>
                </li>
                <li>
                    <a>审批中心</a>
                </li>
                <li class="active">
                    <strong>审批中心</strong>
                </li>
            </ol>
        </div>
    </div>

    <div class="wrapper wrapper-content animated fadeInRight">

        <div class="ibox-content m-b-sm border-bottom">
            <div class="row">
                <form role="form" class="form-horizontal">
                    <div class="form-group">
                        <label class=" col-sm-1 control-label">类型</label>
                        <div class=" col-sm-1">
                            <select class="form-control" v-model="cjQuery.leaveType">
                                <option value="-1">
                                    全部
                                </option>
                                <option value="0">
                                    请假
                                </option>
                                <option value="1">
                                    出差
                                </option>
                            </select>
                        </div>
                        <label class=" col-sm-1 control-label">起始时间</label>
                        <div class=" col-sm-2">
                            <input type="date" class="form-control" v-model="cjQuery.starttime" placeholder="请输入时间">
                        </div>
                        <label class=" col-sm-1 control-label">结束时间</label>
                        <div class=" col-sm-2">
                            <input type="date" class="form-control" v-model="cjQuery.endtime" placeholder="请输入时间">
                        </div>
                        <label class=" col-sm-1 control-label">状态</label>
                        <div class=" col-sm-1">
                            <select class="form-control" v-model="cjQuery.leaveState">
                                <option value="-1">
                                    全部
                                </option>
                                <option value="0">
                                    未审批
                                </option>
                                <option value="1">
                                    审批通过
                                </option>
                                <option value="2">
                                    审批未通过
                                </option>

                            </select>
                        </div>

                        <div>
                            <button class="btn btn-primary btn-sm" type="button" @click="loadData()"><span
                                    class="glyphicon glyphicon-zoom-in"></span> 查询
                            </button>
                        </div>
                    </div>
                </form>

            </div>

        </div>
        <div class="row">
            <div class="col-lg-12">

                <div class="ibox float-e-margins">

                    <div class="ibox-content">

                        <table class="footable table table-stripped toggle-arrow-tiny" data-page-size="15">
                            <thead>
                            <tr>

                                <th data-toggle="true">编号</th>
                                <th data-hide="phone">用户ID</th>
                                <th data-hide="all">类型</th>
                                <th data-hide="phone">起始时间</th>
                                <th data-hide="phone">截止时间</th>
                                <th data-hide="phone">请假理由</th>
                                <th data-hide="phone">审核状态</th>
                                <th data-hide="phone">未通过原因</th>
                                <th class="text-right" data-sort-ignore="true">操作</th>

                            </tr>
                            </thead>
                            <tbody>
                            <tr v-for="(x,index) in list">
                                <td>{{index+1}}</td>
                                <td>{{x.sysId}}</td>
                                <!--                                <td>{{x.leaveType}}</td>-->
                                <td v-if="x.leaveType==0">请假</td>
                                <td v-if="x.leaveType==1">出差</td>
                                <td>{{x.starttime}}</td>
                                <td>{{x.endtime}}</td>
                                <td>{{x.reason}}</td>
                                <td v-if="x.leaveState==0">未审批</td>
                                <td v-if="x.leaveState==1">审批通过</td>
                                <td v-if="x.leaveState==2">审批未通过</td>
                                <!-- <td>{{x.leaveState}}</td>-->
                                <td>{{x.nopassReason}}</td>
                                <td class="text-right" v-if="x.leaveState==0">
                                    <button class="btn-primary btn btn-sm" @click="update(x)"><span
                                            class="glyphicon glyphicon-tag"></span>审批
                                    </button>
                                </td>
                                <td class="text-right" v-else>
                                    <button class="btn-primary btn btn-sm" @click="update(x)" disabled><span
                                            class="glyphicon glyphicon-tag"></span>审批
                                    </button>
                                </td>
                            </tr>
                            </tbody>
                        </table>

                        <div>
                            一共{{total}}条数据,一共{{totalPage}}页,当前第{{curPage}}页
                            <button class="btn btn-success btn-sm" type="button" @click="prePages()">上一页</button>
                            <button class="btn btn-success btn-sm" type="button" @click="nextPages()">下一页</button>
                            <button class="btn btn-success btn-sm" type="button" @click="indexPage()">首页</button>
                            <button class="btn btn-success btn-sm" type="button" @click="endPage()">尾页</button>
                            跳转到<input type="number" id="num" style="width: 40px" min="1" max="10" v-model="selectPage"
                                      @keyup="valNum">页
                            <button class="btn btn-success btn-sm" type="button" @click="changePage()">跳转</button>
                            <select v-model="cjQuery.row" @change="selectRow">
                                <option value="3">每页3条</option>
                                <option value="5">每页5条</option>
                                <option value="10">每页10条</option>
                            </select>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 模态框开始 -->
    <div id="one" class="modal fade" style="top:200px">
        <div class="modal-dialog">

            <div class="modal-content">
                <!--头部-->
                <div class="modal-header">
                    <h4 align="center">差假审批</h4>

                </div>
                <!--主题内容-->
                <div class="modal-body">
                    <form role="form" class="form-horizontal">

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">用户ID</label>
                            <div class=" col-sm-10">
                                <input type="text" class="form-control" v-model="leavess.sysId" readonly="readonly">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">类型</label>
                            <div class=" col-sm-10">
                                <select class="form-control" v-model="leavess.leaveType" readonly="readonly">
                                    <option value="0">请假</option>
                                    <option value="1">出差</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">起始时间</label>
                            <div class=" col-sm-10">
                                <input type="date" class="form-control" v-model="leavess.starttime" placeholder="请输入时间" readonly="readonly">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">截止时间</label>
                            <div class=" col-sm-10">
                                <input type="date" class="form-control" v-model="leavess.endtime" placeholder="请输入时间" readonly="readonly">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class=" col-sm-2 control-label">请假理由</label>
                            <div class=" col-sm-10">
                                <textarea class="form-control" v-model="leavess.reason" placeholder="请输入理由" readonly="readonly"></textarea>
                                <!-- <input type="text" >-->
                            </div>
                        </div>
                        <div class="form-group">
                            <label class=" col-sm-2 control-label">审批</label>
                            <div class=" col-sm-10">
                                <select  class="form-control" v-model="leavess.leaveState">
                                    <option value="1">同意</option>
                                    <option value="2">不同意</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class=" col-sm-2 control-label">不通过原因</label>
                            <div class=" col-sm-10">
                                <textarea v-model="leavess.nopassReason" ></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class=" col-sm-2 control-label">审核人</label>
                            <div class=" col-sm-10">
                                <input v-model="leavess.reviewer" readonly="readonly" >
                            </div>
                        </div>
                    </form>
                </div>

                <!--底部-->
                <div class="modal-footer">
                    <button class="btn btn-primary btn-sm" type="button" @click="closeWin()"><span
                            class="glyphicon glyphicon-remove"></span>关闭
                    </button>
                    <button class="btn btn-primary btn-sm" @click="saveAdmin"><span
                            class="glyphicon glyphicon-save"></span>保存
                    </button>
                </div>

            </div>
        </div>
    </div>
<!--    <span id="sysId" th:text="${sysId}" hidden="hidden"></span>-->
    <span id="sysName" th:text="${sysName}" hidden="hidden"></span>
</div>

</body>

<script>

    new Vue({
        el: "#admin",
        data: {
            list: [],
            total: 0,//总条数
            totalPage: 0,//总页数
            selectPage: 1,//选择页数
            cjQuery: { //查询对象
                page: 1,
                row: 3,
                sysId: null,//用户ID 先写死！！！！
                starttime: null,
                endtime: null,
                leaveState: -1,
                leaveType: -1
            },
            prePage: 0,//上一页
            nextPage: 0,//下一页.
            curPage: 0,//当前页

            leavess: {
                sysId: 1,
                leaveType: "",
                starttime: "",
                endtime: "",
                reason: "",
                leaveState: 0,
                nopassReason: "",
                reviewer:""
            },

        },
        methods: {
            loadData: function () {
                var self = this;
                $.ajax({
                    url: "http://192.168.7.36:2021/cj-service/leavess/list",//请求地址
                    type: "post",
                    data: self.cjQuery,
                    contentType: "application/x-www-form-urlencoded",
                    dataType: "json",//返回的数据类型
                    success: function (data) {
                        console.log(data);
                        self.list = data.list;
                        self.total = data.total;
                        self.totalPage = data.totalPage;
                        self.prePage = data.prePage;
                        self.nextPage = data.nextPage;
                        self.curPage = data.curPage;
                    }
                })
            },
            getName:function(){
                var self = this;
                var sysName = $("#sysName").text();
                console.log(sysName)
                $.ajax({
                    url:"http://192.168.7.36:2021/personnel-service/personnel/personneltwo",
                    type:"get",
                    data:{"sysName":sysName},
                    dataType:"json",
                    success:function (data) {
                        self.leavess.reviewer = data.userName;
                        console.log(self.leavess.reviewer)
                    }
                })
            },
            prePages: function () {//上一页
                this.cjQuery.page = this.prePage;
                //刷新
                this.loadData();

            },
            nextPages: function () {
                console.log(this.cjQuery)
                console.log(this.nextPage)
                this.cjQuery.page = this.nextPage;
                // //刷新
                console.log(this.cjQuery.page)
                this.loadData();

            },
            indexPage: function () {//首页
                this.cjQuery.page = 1
                //刷新
                this.loadData();

            },
            endPage: function () {//尾页
                this.cjQuery.page = this.totalPage;
                //刷新
                this.loadData();

            },
            changePage: function () {//跳转
                if (this.selectPage > this.totalPage) {
                    this.cjQuery.page = this.totalPage;
                } else {
                    this.cjQuery.page = this.selectPage;
                }
                //刷新
                this.loadData();

            },
            selectRow: function () {//选择条数
                this.cjQuery.page = 1
                //刷新
                this.loadData();

            },
            valNum: function () {
                //定义正则表达式对象
                var dd = /^[\u4e00-\u9fa5]{0,}$/
                //如果输入的汉字，就显示1
                if (dd.test(this.selectPage)) {
                    this.selectPage = 1
                } else {
                    console.log("==" + this.selectPage)
                    //如果输入的值大于总页数，就回到最大值
                    if (this.selectPage > this.totalPage) {
                        this.selectPage = this.totalPage;
                    }
                }


            },
            update: function (x) {//打开修改模态框
                $("#one").modal("show")
                //数据回显
                console.log(x)
                x.reviewer=this.leavess.reviewer
                this.leavess = x;

            },
            saveAdmin: function () {//保存
                var self = this;
                $.ajax({
                    url: "http://192.168.7.36:2021/cj-service/leavess/update",
                    type: "post",
                    contentType: "application/x-www-form-urlencoded",
                    data: self.leavess,
                    dataType: "json",
                    success: function (data) {
                        console.log(data);
                        alert(data.info);
                        if (data.info == "保存成功") {
                            //关闭模态框
                            $("#one").modal("hide")
                            //刷新
                            self.loadData();
                        }else if(data.info=="用户此月请假机会也用完"){
                            alert(data.info)
                            $("#one").modal("hide")
                            self.loadData();
                        }
                    }


                })

            },
            closeWin: function () {//关闭模态框
                $("#one").modal("hide")
            }


        },
        mounted() {
            //运行loadData函数
            this.loadData();
            this.getName();
        }
    })


</script>
</html>
